<div class="row">
  <div class="col-xs-12">
      <div class="box box-primary">
          <div class="box-header">
            <h3 class="box-title">Surat Jaminan</h3>
            <span class="box-title tmb-title">
            	<a href="<?php echo site_url('surat_jaminan/add')?>" class="btn btn-xs btn-primary btn-flat"><i class="ion-plus-round"></i>&nbsp;&nbsp;Tambah</button></a>
            </span>
            <div class="box-tools box-cari">
              
          	</div>
          </div><!-- /.box-header -->
          <div class="box-body box-export-tools table-responsive">
          	<span class="notif notif-primary" <?php if(is_string($this->session->flashdata('sukses'))){echo 'style="display:block;"';}else{echo 'style="display:none;"';}?>>
          		<i class="fa fa-check"></i>
          		<?php echo $this->session->flashdata('sukses'); ?>
          		<button type="button" class="close">&times;</button>
          	</span>

          	<span class="notif notif-danger" <?php if(is_string($this->session->flashdata('gagal'))){echo 'style="display:block;"';}else{echo 'style="display:none;"';}?>>
          		<i class="fa fa-check"></i>
          		<?php echo $this->session->flashdata('gagal'); ?>
          		<button type="button" class="close">&times;</button>
          	</span>
          	<?=form_open('surat_jaminan/cari', array('class' => 'form-inline'))?>
						  <div class="form-group">
						    <label class="sr-only" for="exampleInputEmail2">Tanggal Awal</label>
						    <input type="text" name="tgl_awal" value="<?=$this->session->userdata('tgl_awal');?>" class="form-control input-sm" id="tgl_awal" placeholder="Tanggal Awal">
						  </div>
						  <div class="form-group">
						    <label class="sr-only" for="exampleInputPassword2">Tanggal Akhir</label>
						    <input type="text" name="tgl_akhir" value="<?=$this->session->userdata('tgl_akhir');?>" class="form-control input-sm" id="tgl_akhir" placeholder="Tanggal Akhir">
						  </div>
						  <div class="form-group">
						    <label class="sr-only" for="exampleInputPassword2">Jenis Kunjungan</label>
						    <select name="jenis_kunjungan" class="form-control input-sm" id="jenis_kunjungan">
						    	<option value=""> - - Pilih Jenis Kunjungan - - </option>
						    	<?php
						    		foreach ($jenis_kunjungan as $value) {
						    			if($value['id_jenis_kunjungan'] == $this->session->userdata('jenis_kunjungan')){
						    				$s = "selected";
						    			}else{
						    				$s = "";
						    			}
						    			echo "<option value=".$value['id_jenis_kunjungan']." $s>".$value['jenis_kunjungan']."</option>";
						    		}
						    	?>
						    </select>
						  </div>
						  <div class="form-group">
						    <label class="sr-only">Status</label>
						    <select name="status" class="form-control input-sm" id="status">
						    	<option value=""> - - Pilih Status - - </option>
						    	<?php
						    		if($this->session->userdata('status') == 'Diterima'){
					    				$sd = "selected";
					    				$st = "";
					    				$sp = "";
					    			}else if($this->session->userdata('status') == 'Ditolak'){
					    				$sd = "";
					    				$st = "selected";
					    				$sp = "";
					    			}else if($this->session->userdata('status') == 'Pending'){
					    				$sd = "";
					    				$st = "";
					    				$sp = "selected";
					    			}else{
					    				$sd = "";
					    				$st = "";
					    				$sp = "";
					    			}
						    	?>
						    	<option <?php echo $sd; ?>>Diterima</option>
						    	<option <?php echo $st; ?>>Ditolak</option>
						    	<option <?php echo $sp; ?>>Pending</option>
						    </select>
						  </div>
						  <div class="input-group">
                <input type="text" name="keyword" value="<?=$this->session->userdata('keyword');?>"class="form-control input-sm pull-right" placeholder="Cari nama/kode jaminan..."/>
                <div class="input-group-btn">
                  <button type="submit" name="submit" class="btn btn-sm btn-default btn-flat"><i class="fa fa-search"></i></button>
                </div>
              </div>
						<?=form_close();?>
          	<div class="pull-right">
            	<a href="<?php echo site_url('surat_jaminan/excel')?>" class="btn btn-xs btn-tbl btn-flat"><i class="fa fa-file-excel-o"></i>&nbsp;&nbsp;Save as Excel</button></a>
              <!-- <a href="<?php echo site_url('surat_jaminan/pdf')?>" target="_blank" class="btn btn-xs btn-tbl btn-flat"><i class="fa fa-file-pdf-o"></i>&nbsp;&nbsp;Save as PDF</button></a>  	 -->
            </div>
            <table class="table table-hover table-condensed table-striped">
							<thead>
							<tr>
								<th style="text-align:center;" width="3%">#</th>
								<th width="10%">Kode Jaminan</th>
								<th width="6%">Status</th>
								<th width="8%">Tanggal</th>
								<th width="20%">Nama Pasien</th>
								<th width="5%">JK</th>
								<th width="15%">Alamat</th>
								<th width="10%">Kunjungan</th>
								<th width="10%">Kode Klaim</th>
								<th width="15%"></th>
							</tr>
							</thead>
							<?php 
								if(!empty($results)){
									foreach ($results as $row) {
										?>
										<tr>
											<td align="center"><?php echo $ordinal_num++ ?></td>
											<td><?php echo $row['kd_surat_jaminan']?></td>
											<td>
												<?php 
													if($row['status_jaminan'] == 'Diterima'){
														echo "<span class='label label-success'>Diterima</span>";
													}else if($row['status_jaminan'] == 'Ditolak'){
														echo "<span class='label label-danger'>Ditolak</span>";
													}else{
														echo "<span class='label label-warning'>Pending</span>";
													}
												?>
											</td>
											<td><?php echo id_date($row['tgl_surat'])?></td>
											<td><?php echo $row['nama']?></td>
											<td><?php echo $row['jk']?></td>
											<td><?php echo $row['alamat']?></td>
											<td><?php echo $row['jenis_kunjungan']?></td>
											<td><?php echo $row['kd_klaim']?></td>
											<td>
												<span class="pull-right">
													<?php echo anchor('surat_jaminan/detail/'.$row['kd_klaim'].'','Lihat','class="label label-primary" title="Lihat data surat jaminan"'); ?>
													<?php echo anchor('surat_jaminan/edit/'.$row['kd_klaim'].'','Edit','class="label label-warning" title="Edit data surat jaminan"'); ?>
													<?php
														if($row['tgl_klaim'] == '0000-00-00'){
															echo anchor('surat_jaminan/delete/'.$row['kd_klaim'].'','Hapus','class="label label-danger" title="Hapus data surat jaminan" onClick="return confirm(\'Yakin ingin menghapus '.$row['nama'].' dari data surat jaminan?\');"'); 
														}else{
															?>
																<a href="#" class="label label-default" title="Hapus data surat jaminan" onClick="return alert('Surat jaminan tidak dapat dihapus karena sudah digunakan untuk klaim!')">Hapus</a> 
															<?php
														}
													?>
												</span>
											</td>
										</tr>
										<?php 
									}
								}else{
							?>
							<tr>
								<td colspan="10" align="center">Tidak ada data</td>
							</tr>
							<?php
								}
							?>							
						</table>									
          </div><!-- /.box-body -->
          <div class="box-footer clearfix">
            <ul class="pagination pagination-sm no-margin pull-right">
              <?php echo $pagination; ?>
            </ul>        
          </div>
      </div><!-- /.box -->                            
  </div>
</div>

<script type="text/javascript">
  $(document).ready(function(){
    $('#tgl_awal, #tgl_akhir').datepicker({
      dateFormat: "dd/mm/yy",
      changeMonth: true,
      changeYear: true
    });
  });
</script>   